package com.hualan.sfzy.service.counselor.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.counselor.CounselorOrder;
import com.hualan.sfzy.mapper.counselor.CounselorOrderMapper;
import com.hualan.sfzy.service.counselor.CounselorOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("CounselorOrderService")
public class CounselorOrderServiceImpl implements CounselorOrderService {

    @Autowired
    private CounselorOrderMapper counselorOrderMapper;

    @Override
    public int add(CounselorOrder entity) {
        return counselorOrderMapper.insert(entity);
    }

    @Override
    public int edit(CounselorOrder entity) {
        return counselorOrderMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return counselorOrderMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return counselorOrderMapper.deleteBatch(ids);
    }

    @Override
    public List<CounselorOrder> find() {
        return counselorOrderMapper.select(null);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, CounselorOrder entity) {
        PageHelper.startPage(pageNum, pageSize);

        List<CounselorOrder> list = counselorOrderMapper.select(entity);

        PageInfo<CounselorOrder> PageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();

        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,PageInfo.getPages());
        map.put(CommonConstant.TOTAL,PageInfo.getTotal());

        return map;
    }

    @Override
    public CounselorOrder findById(Integer id) {
        return counselorOrderMapper.selectById(id);
    }

}
